package archive;

import players.Player;
import model.Field;
import model.Game;
import model.OthelloBoard;

public class TrialRun
{
    Player d_whiteplayer;
    Player d_blackplayer;
    
    int d_trailcount;
    
    public TrialRun(Player whiteplayer, Player blackplayer, int trailcount)
    {
        d_whiteplayer = whiteplayer;
        d_blackplayer = blackplayer; 
        d_trailcount  = trailcount;
    }
    
    public GameExample [] run(boolean loggamesmode)
    {
        GameExample [] examples = null;
        if(loggamesmode)
            examples = new GameExample[d_trailcount]; // an array containing a record of all games played.
        //int callcounter = 0; used to measure calls in performance runs.
        int [] wins = new int [3];
        for(int trail = 0; trail < d_trailcount; trail++)
        {           
            //initialize board here, not in play() as then the players have a different board.
            Game game = play();
            wins[game.getWinner()]++;
            if(loggamesmode)
                examples[trail] = new GameExample(game);
        }
        System.out.println("White:\t" +  wins[Field.WHITE] * 100.0 / d_trailcount + "%");
        System.out.println("Black:\t" +  wins[Field.BLACK] * 100.0 / d_trailcount + "%");
        System.out.println("Nobody:\t" + wins[Field.EMPTY] * 100.0 / d_trailcount + "%");
        return examples;
    }
    
    
    public Game play()
    {   
        
        Game game = new Game();
//        
//        OthelloBoard board = new OthelloBoard();
//
//        boolean p1MadeMove = true;
//        boolean p2MadeMove = true;
//        
//        while (p1MadeMove || p2MadeMove){
//            p1MadeMove = d_whiteplayer.move(board, Field.WHITE);
//            if (p1MadeMove)
//                game.addBoard(board.toArray(Field.WHITE), Field.WHITE);
//            
//            p2MadeMove = d_blackplayer.move(board, Field.BLACK);
//            if (p2MadeMove)
//                game.addBoard(board.toArray(Field.BLACK), Field.BLACK);
//        }
//        game.setWinner(board.bestPlayer());
        return game;
    }
}
